//
//  MoreViewController.m
//  LOL_PalmarHelper
//
//  Created by dllo on 15/6/19.
//  Copyright (c) 2015年 hantao. All rights reserved.
//

#import "MoreViewController.h"

@interface MoreViewController ()

@end

@implementation MoreViewController

- (void)dealloc
{
    [_tableV release];
    [_mycell release];

    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor clearColor];
    self.navigationItem.title = @"更多";
    
    
    self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.frame.size.height - self.navigationController.tabBarController.tabBar.bounds.size.height - self.navigationController.navigationBar.bounds.size.height) style:UITableViewStyleGrouped];
    self.tableV.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    

//    self.tableV.bounces = NO;.
    
    [self.view addSubview:self.tableV];
    
   
    
    
    [_tableV release];
    
    
       
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self.tableV reloadData];
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    
    if (indexPath.row == 0 && indexPath.section == 0) {
        
        EquipmentViewController *equipment = [[EquipmentViewController alloc] init];
        
        [self.navigationController pushViewController:equipment animated:YES];
        
        
    }
    
    if(indexPath.section == 0 && indexPath.row == 1) {
        
        
        skillViewController *skill = [[skillViewController alloc] init];
        [self.navigationController pushViewController:skill animated:YES];
        
        [skill release];
    }
    
    
    if (indexPath.section == 1 && indexPath.row == 0) {
        
        SearchViewController *search = [[SearchViewController alloc] init];
      
        [self.navigationController pushViewController:search animated:YES];
        [search release];
    }
    
    if (indexPath.section == 1 && indexPath.row == 2)
    {
        
        OffcialForumController *offcialVC = [[OffcialForumController alloc] init];
        
        offcialVC.myname = @"LOL 官方论坛";
        
        offcialVC.myurl = @"http://bbs.lol.qq.com/forum.php";
        
        [self.navigationController pushViewController:offcialVC animated:YES];
        
        
        [offcialVC release];
    }
    
    if (indexPath.section == 1 && indexPath.row == 1)
    {
        
        HideWebViewController *offcialVC = [[HideWebViewController alloc] init];
        
        offcialVC.myurl = @"http://test.lolhelper.cn/";
        
        [self.navigationController pushViewController:offcialVC animated:YES];
        
         [offcialVC release];
    }

    if (indexPath.section == 1 && indexPath.row == 3)
    {
        
        LiveVideoViewController *liveVC = [[LiveVideoViewController alloc] init];
        
        [self.navigationController pushViewController:liveVC animated:YES];
        
        [liveVC release];
        
    }
    
    
    if (indexPath.section == 2 && indexPath.row == 2) {
        
        AboutWeViewController *aboutWe = [[AboutWeViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:aboutWe];
        
        [self presentViewController:nav animated:YES completion:^{
            
            
        }];
        
    }
    if(indexPath.section == 2 && indexPath.row == 0){
        CollectViewController *coll = [[CollectViewController alloc] init];
        [self.navigationController pushViewController:coll animated:YES];
        [coll release];
        
        
        
    }
    

    
    if (indexPath.section == 2 && indexPath.row == 1) {
        
        
        
        NSUInteger size = [[SDImageCache sharedImageCache] getSize];
        
        CGFloat mb = size / 1024.0 / 1024.0;
//        NSLog(@"%f",mb);
        self.Mb = [NSString stringWithFormat:@"缓存数据:%.2fMB",mb];
        UIAlertView *al = [[UIAlertView alloc] initWithTitle:self.Mb message:@"是否清除缓存?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        al.delegate = self;
        [al show];
        
        
    }
    
    
    
    


}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if (buttonIndex == 1) {
        
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSString *cachpath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0];
            NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachpath];
            
            for (NSString *p in files) {
                NSError *error;
                NSString *path = [cachpath stringByAppendingPathComponent:p];
                if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                    [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
                }
            }
            
        });
      }





}





-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 3;
}




//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
//{
//    return self.view.bounds.size.height - 115;
//}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
  
    return 45;
   
}






-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    if (section == 0) {
        
        return 2;
    }else if (section == 1) {
    
    
        return 4;
    }else  {
    
        return 3;
    
    }
    
    
    
}





-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

      static NSString *indentifier = @"myCell";
   MoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (cell == nil) {
        
        cell = [[MoreTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
        
    }
    
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
//     [tableView setSeparatorColor:[UIColor blueColor]];
    
//     [tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLineEtched];


    if (indexPath.section == 0 && indexPath.row == 0) {
        
        cell.str = @"f10648560d33605f97d55c5338552d89.jpg";
        
        cell.str1 = @"装备";
        

    
    }
    if(indexPath.section == 0 && indexPath.row == 1){
        cell.str = @"0a6dc6e04019a489ca568f8059ef34c4.jpg";
        cell.str1 = @"召唤师技能";
        
    }

    
    if (indexPath.section == 1 && indexPath.row == 0) {
        
        cell.str = @"c55d5d07712f9bb0d55629f57d3ee51a.jpg";
        
        cell.str1 = @"战斗力查询";
        


    }
    
    if (indexPath.section == 1 && indexPath.row == 1) {
        
        cell.str = @"b6cc31de9cd83723de9a42ea249ac8e6.jpg";
        
        cell.str1 = @"隐藏分查询";
        


    }
    
    if (indexPath.section == 1 && indexPath.row == 2) {
        
        cell.str = @"6f7b74aa8ed5f175d1bec80c429a3fd9.jpg";
        
        cell.str1 = @"LOL 官方论坛";
        

        
    }

    if (indexPath.section == 1 && indexPath.row == 3) {
        
        cell.str = @"3d594f6689ac0db6b6bb515362cae5e0.jpg";
        
        cell.str1 = @"直播间";
        

        
    }

  
    if (indexPath.section == 2 && indexPath.row == 2) {
        
        cell.str = @"2a6d7529c8328de1179d29506c53c5ff.jpg";
        
        cell.str1 = @"关于我们";
        
        
    }
    if(indexPath.section == 2 && indexPath.row == 0){
        cell.str = @"image.png";
        cell.str1 = @"我的收藏";
        
        
    }
    
    
    
    if (indexPath.section == 2 && indexPath.row == 1) {
        
        cell.str = @"4826b5e92585ed91738e5259f1daba54.jpg";
        cell.str1 = @"清空缓存";
        
    }
    
  
    
    
    return cell;
}












- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
